<?php
/**
 * 
 * @author z.En Wong
 * @since version 1.1 - 2009-07-14
 * @uses 方便的创建HTML页面
 * 
 */
?>
<?php
	
	function html_BBCode2html__($content){

		$a1 = array(
					'[img]',
					'[/img]',
					'[b]',
					'[/b]',
					'[i]',
					'[/i]',
					);
		$a2 = array(
					'<img src="',
					'" />',
					'<strong>',
					'</strong>',
					'<em>',
					'</em>',
					);
		return str_replace($a1,$a2,$content);
	}
	
	function html_showMessages_($message='',$color='',$LText='',$RText='') {
			if (isset($message) && $message!='') {
				if (strlen($color)>0) {
					echo $LText."<span style='color:".$color.";'>".$message."</span>".$RText;
				}else {
					echo $LText.$message.$RText;
				}
			}
	}
	function html_Img_($src,$id='',$border=0,$alt='',$other=''){
		$img = "<img src=\"{$src}\" id=\"{$id}\" border=\"{$border}\" ";
		$img .= $alt==''?" alt=\"{$alt}\" {$other}>":" {$other}>";
		echo $img;
	}

	function html_Form_L_($action = '', $enctype = '', $other = '', $id = 'zform', $name = 'zform', $method = 'post') {
//		GLOBAL $fIndex;
//		GLOBAL $line;
		$form = "<form";

		if ($id == 'zform') {
			$form .= " id='".$id . self::$fIndex . "'";
		} else {
			$form .= " id='" .$id. "'";
		}
		if ($name == 'zform') {
			$form .= " name='". $name . self::$fIndex . "'";
		} else {
			$form .= " name='". $name ."'";
		}

		if ($enctype != '') {
			$form .= " enctype='".$enctype."'";
		}

		$form .= " method='".$method."'";
		$form .= " action='".$action."'";
		$form .= " ".$other;
		$form .= " />";

		
		echo $form;
	}
	function html_Form_R_() {
//		GLOBAL $line;
		echo "</form>";
	}
	
	function html_Print_($text=''){
		echo $text;
	}

	function html_Text_($name = '', $value = '', $id = '', $other = '') {
//		GLOBAL $line;
		$text = "<input";
		$text .= " id='".$id."'";
		$text .= " name='".$name."'";
		$text .= " type='text'";
		$text .= " value='".$value."'";
		$text .= " ".$other;
		$text .= "/>";
		echo $text;
	}
	function html_TextArea_($name = '', $value = '', $id = '', $other = '') {
//		GLOBAL $line;
		$textArea = "<textarea";
		$textArea .= " id='".$id."'";
		$textArea .= " name='".$name."'";
		$textArea .= " ".$other.">";
		$textArea .= $value;
		$textArea .= "</textarea>";

		echo $textArea;
	}

	function html_Password_($name = '', $value = '', $id = '', $other = '') {
//		GLOBAL $line;
		$pwd = "<input";
		$pwd .= " id='".$id."'";
		$pwd .= " name='".$name."'";
		$pwd .= " type='password'";
		$pwd .= " value='".$value."'";
		$pwd .= " ".$other;
		$pwd .= "/>";
		echo $pwd;
	}

	function html_Hidden_($name = '', $value = '', $id = '', $other = '') {
//		GLOBAL $line;

		$hidden = "<input";

		$name = $name == "" ? 'hiddenField' : $name;

		if ($id != '') {
			$hidden .= " id='".$id."'";
		}

		$hidden .= " name='".$name."'";
		$hidden .= " type='hidden'";
		$hidden .= " value='".$value."'";
		$hidden .= " ".$other;
		$hidden .= "/>";

		echo $hidden;
	}

	function html_CheckBox_($name = '', $value = '', $equalCheckedValue = '', $id = '', $other = '') {
//		GLOBAL $line;

		$checkBox = "<input";

		if ($id != '') {
			$checkBox .= " id='".$id."'";
		}

		$checkBox .= " name='".$name."'";
		$checkBox .= " type='checkbox'";
		$checkBox .= " value='".$value."'";

		if ($equalCheckedValue === true || ($equalCheckedValue != '' && $equalCheckedValue == $value)) {
			$checkBox .= " checked='checked'";
		}

		$checkBox .= " ".$other;
		$checkBox .= "/>";

		echo $checkBox;
	}
	
	function html_CheckBox_group_($name,$content_array,$checked_arr_or_str='',$other=''){
		$name_type=count($content_array)>1?"[]":"";
		
		foreach ($content_array as $value => $text){
			$temp_checked='';
			if (!is_array($checked_arr_or_str) && strval($checked_arr_or_str)===strval($value)) {
				$temp_checked="checked=\"checked\"";
			}else if (in_array(strval($value),$checked_arr_or_str)) {
				$temp_checked="checked=\"checked\"";
			}
			echo "<input name=\"{$name}{$name_type}\" type=\"checkbox\" id=\"{$name}_{$value}\"  value=\"{$value}\" {$temp_checked} />";
			echo "<label for=\"{$name}_{$value}\">{$text}</label>".$other;
		}
	}
	
	
	
	
	
	

	function html_RadioBox_($name = '', $value = '', $equalCheckedValue = '', $id = '', $other = '') {

		$radioBox = "<input";

		if ($id != '') {
			$radioBox .= " id='".$id."'";
		}

		$radioBox .= " name='".$name."'";
		$radioBox .= " type='radio'";
		$radioBox .= " value='".$value."'";

		if ($equalCheckedValue === true || ($equalCheckedValue != '' && $equalCheckedValue == $value)) {
			$radioBox .= " checked='checked'";
		}
		$radioBox .= " ".$other;
		$radioBox .= "/>";

		echo $radioBox;
	}
	
	function html_RadioBox_group_($name,$content_array,$checked_str='',$other=''){
		foreach ($content_array as $value => $text){
			$temp_checked='';
			if (strval($checked_str)===strval($value)) {
				$temp_checked="checked=\"checked\"";
			}
			echo "<input name=\"{$name}\" type=\"radio\" id=\"{$name}_{$value}\" value=\"{$value}\" {$temp_checked} />";
			echo "<label for=\"{$name}_{$value}\">{$text}</label>".$other;
			$temp_checked='';

		}
	}
	
	
	function html_Select_L_($name = '', $id = '', $multiple = false, $size = '', $other = '') {

		$select = "<select";

		if ($id != '') {
			$select .= " id='".$id."'";
		}

		$select .= " name='".$name."'";

		if ($size != '') {
			$select .= " size='".$size."'";
		}

		if ($multiple == true) {
			$select .= " multiple='MULTIPLE'";
		}

		$select .= " ".$other;
		$select .= ">";

		echo $select;

	}

	function html_Select_R_() {


		echo "</select>";
	}

	function html_Option_($text = '', $value = '', $equalCheckedValueOrArr = '', $id = '', $other = '') {


		$option = "\t<option";

		if ($id != '') {
			$option .= " id='".$id."'";
		}

		if ($value != '') {
			$option .= " value='".$value."'";
		}

		if (is_array($equalCheckedValueOrArr)) {
			if ($equalCheckedValueOrArr != '' && in_array($value, $equalCheckedValueOrArr)) {
				$option .= " selected='selected'";
			}
		} else {
			if ($equalCheckedValueOrArr == true || ($equalCheckedValueOrArr != '' &&  $value == $equalCheckedValueOrArr )) {
				$option .= " selected='selected'";

			}
		}

		$option .= " ".$other;
		$option .= ">";
		$option .= $text;
		$option .= "</option>";

		echo $option;
	}

	function html_File_($name = '', $id = '', $other = '') {


		$name = $name == "" ? 'file' : $name;

		$file = "<input";

		if ($id != '') {
			$file .= " id='".$id."'";
		}

		$file .= " name='".$name."'";
		$file .= " type='file'";
		$file .= " ".$other;
		$file .= "/>";

		echo $file;
	}

	function html_Submit_($name = '', $value = 'Submit', $id = 'Submit', $other = '') {
//		GLOBAL $line;

		if ($value=='') {
			$value='Submit';
		}
		if ($id=='') {
			$id='Submit';
		}

		$name = $name == "" ? 'Submit' : $name;

		$submit = "<input";

		if ($id != '') {
			$submit .= " id='".$id."'";
		}

		$submit .= " type='submit'";
		$submit .= " name='".$name."'";
		$submit .= " value='".$value."'";
		$submit .= " ".$other;
		$submit .= "/>";

		echo $submit;

	}

	function html_Reset_($name = '', $value = 'Reset', $id = 'Reset', $other = '') {
//		GLOBAL $line;

		$name = $name == "" ? 'Reset' : $name;

		$reset = "<input";

		if ($id != '') {
			$reset .= " id='".$id."'";
		}

		$reset .= " type='reset'";
		$reset .= " name='".$name."'";
		$reset .= " value='".$value."'";
		$reset .= " ".$other;
		$reset .= "/>";

		echo $reset;
	}

	function html_Button_($name = '', $value = 'Button', $id = '', $other = '') {
//		GLOBAL $line;

		$buttont = "<input";

		if ($id != '') {
			$buttont .= " id='".$id."'";
		}

		$buttont .= " type='button'";
		$buttont .= " name='".$name."'";
		$buttont .= " value='".$value."'";
		$buttont .= " ".$other;
		$buttont .= "/>";

		echo $buttont;
	}

?>